﻿namespace DotNetMigrations.Commands
{
    [ConsoleCommand("rollback")]
    public class RollbackCmd : ConsoleCommand
    {
        public RollbackCmd(string[] args) : base(args) { }

		//private int _rollbackCount = 1;

		public override bool ValidateArgs()
		{
			if (ArgCount < 1)
			{
				Output.Warn("Connection string not found");
				return false;
			}

			DAL.ConnectionString = ArgFetcher.GetConnectionString(Args);

            //if (ArgCount >= 2)
            //{
            //    _rollbackCount = ArgFetcher.GetFirstNumericArg(Args);
            //}

    		return true;
		}

		public override bool Run()
		{
		    long previousVersion = MigrationScript.GetPreviousMigrationVersion();
           
            return Database.Migrate(previousVersion);
		}
    }
}
